// pages/ced/ced.js
const axios = require('../logs/axios');
import * as echarts from '../../ec-canvas/echarts';
var data = [["2000-06-05",116],["2000-06-06",129],["2000-06-07",135],["2000-06-08",86],["2000-06-09",73],["2000-06-10",85],["2000-06-11",73],["2000-06-12",68],["2000-06-13",92],["2000-06-14",130],["2000-06-15",245],["2000-06-16",139],["2000-06-17",115],["2000-06-18",111],["2000-06-19",309],["2000-06-20",206],["2000-06-21",137],["2000-06-22",128],["2000-06-23",85],["2000-06-24",94],["2000-06-25",71],["2000-06-26",106],["2000-06-27",84],["2000-06-28",93],["2000-06-29",85],["2000-06-30",73],["2000-07-01",83],["2000-07-02",125],["2000-07-03",107],["2000-07-04",82],["2000-07-05",44],["2000-07-06",72],["2000-07-07",106],["2000-07-08",107],["2000-07-09",66],["2000-07-10",91],["2000-07-11",92],["2000-07-12",113],["2000-07-13",107],["2000-07-14",131],["2000-07-15",111],["2000-07-16",64],["2000-07-17",69],["2000-07-18",88],["2000-07-19",77],["2000-07-20",83],["2000-07-21",111],["2000-07-22",57],["2000-07-23",55],["2000-07-24",60]];
var dateList = data.map(function (item) {
    return item[0];
});
var valueList = data.map(function (item) {
    return item[1];
});
var d1;
const url = 'index.php/admin/ifi/index?cist=economy';
axios.post(url).then((res)=>{
  // console.log(res);
  d1 = res.data[0];
  delete d1.id;
  delete d1.openid;
});
function initChart(canvas,width,height) {//折线图
  const myChart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(myChart);
  var option = {
    visualMap: [{
      show: false,
      type: 'continuous',
      seriesIndex: 0,
      min: 0,
      max: 100,
      aa:1
  }],
  tooltip: {
      trigger: 'axis'
  },
  xAxis: [{
      show:false,//隐藏x轴
      data:d1
  }],
  yAxis: [{
    show:false,//隐藏y轴
    data:d1
  }],
  grid: [{
      bottom: '0%'
  }],
  series: [{
      type: 'line',
      showSymbol: false,
      data: valueList,
      itemStyle:{
        normal:{
          lineStyle:{
            color:'#ffffff',
            width:3
          }
        }
      }
  }]
  };
  // var myChart = echarts.init(document.getElementById('myChart'))
  // myChart.setOption(option)
  // setTimeout(function(){
  //   window.onresize=function(){
  //     myChart.resize();
  //   }
  // },200)
  
  option && myChart.setOption(option);

}
Page({
  
  /**
   * 页面的初始数据
   */
  data: {
    list:'',
    openid:'',
    TabCur: 0,
    scrollLeft:0,
    data:'1',
    top:'1',
    equ:'',//办公
    fc:'',//房产
    jx:'',//机械
    ys:'',//运输
    a:'',//房产
    b:'',//房产
    c:'',//房产
    d:'',//房产
    Tab:[
      '租售中','已售','闲置','自居'
    ],
    foot:[
      {id:'0',title:'不动产',time:'2021-09-09'},
    ],
    ec: {//折线图
      onInit: initChart
    },
    array:[
      '本周',"本月","本年"
    ],
    indexss:'',
    index:''
  },
  tabSelect(e) {
    console.log(e);
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id-1)*60
    })
  },
  
  bindPickerChange: function(e) {
    var that=this
    console.log('picker发送选择改变，携带值为', e.detail.value)
    console.log(e);
    that.setData({
      indexss: e.detail.value,
      index:e.detail.value
      // aaa:e.currentTarget.dataset.id
    })
    console.log(that.data.index);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    },
    // oo(){
    //   wx.navigateTo({
    //     url: '/pages/details/details',
    //   })
    // },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.bar();
    var that=this
    wx.getStorage({
      key: 'open',
      success:(res)=>{
        console.log('ces',res.data);
        that.setData({
          openid:res.data,
        })
        // that.onShow();
        console.log(that.data.openid);
        this.qingqiu();
      }
    })
  },
  qingqiu(){  
      var that=this;
      console.log(that.data)
      wx.request({
            url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=week', //仅为示例，并非真实的接口地址
            method:'POST',
            data:{
              openid:that.data.openid,
            },
            success(res) {
              console.log(res)
              that.setData({
                list:res.data
              })
            }
          })
    var that=this
    var ii=wx.getStorageSync('open')
    wx.request({//办公
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=equipments',
      method:'POST',
      data:{
        openid:ii
      },
      success:function(res) {
        console.log(res);
        that.setData({
          equ:res.data
        })
      }
    })
    wx.request({//房产
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=houses',
      method:'POST',
      data:{
        openid:ii
      },
      success:function(res) {
        console.log(res);
        that.setData({
          fc:res.data
        })
      }
    })
    wx.request({//机械
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=mechanicals',
      method:'POST',
      data:{
        openid:ii
      },
      success:function(res) {
        console.log(res);
        that.setData({
          jx:res.data
        })
      }
    })
    wx.request({//运输
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=transportations',
      method:'POST',
      data:{
        openid:ii
      },
      success:function(res) {
        console.log(res);
        that.setData({
          ys:res.data
        })
      }
    })
    wx.request({//租售
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=housess',
      method:'POST',
      data:{
        openid:ii
      },
      success:function(res) {
        console.log(res);
        that.setData({
          a:res.data
        })
      }
    })
    wx.request({//已售
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=housees',
      method:'POST',
      data:{
        openid:ii
      },
      success:function(res) {
        console.log(res);
        that.setData({
          b:res.data
        })
      }
    })
    wx.request({//闲置
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=houseess',
      method:'POST',
      data:{
        openid:ii
      },
      success:function(res) {
        console.log(res);
        that.setData({
          c:res.data
        })
      }
    })
    wx.request({//自居
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=houseeds',
      method:'POST',
      data:{
        openid:ii
      },
      success:function(res) {
        console.log(res);
        that.setData({
          d:res.data
        })
      }
    })
  },
  onTabItemTap() {
    this.bar();
  },
  bar:function(){
    let self = this
    if (!wx.getStorageSync('openid')) {
      wx.showModal({
        title: '提示',
        content: '账号尚未登录，请先登录账号',
        success: res => {
          if (res.confirm) {
            // console.log(res.confirm)
            wx.reLaunch({
              url: '/pages/my/my',
            })
          } else if (res.cancel) {
            wx.reLaunch({
              url: '/pages/logs/logs'
            })
          }
        }
      })
    }
  },
  
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})